package com.example.wumeng.spinner;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

/**
 * 创建日期：2018/4/26 on 14:09
 * 描述:
 * 作者: WuMeng
 */
public class MyAdapter extends BaseAdapter {

    private List<Person> mList;
    private Context mContext;

    public MyAdapter(List<Person> mList, Context mContext) {
        this.mList = mList;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return mList != null ? mList.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater layoutInflater = LayoutInflater.from(mContext);
        convertView = layoutInflater.inflate(R.layout.item_custom,null);
        if (convertView != null) {
            TextView _TextView1 = convertView.findViewById(R.id.text1);
            TextView _TextView2 = convertView.findViewById(R.id.text2);
            _TextView1.setText(mList.get(position).getPersonName());
            _TextView2.setText(mList.get(position).getPersonAddress());
        }
        return convertView;
    }
}
